package com.project.service.imp;

import com.project.bean.GradeBean;
import com.project.bean.UserBean;
import com.project.mapper.IUserMapper;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImp implements IUserService {
    @Autowired
    private IUserMapper mapper;
    @Override
    public UserBean login(String userName, String password) {
        UserBean userBean= mapper.login(userName,password);
        return userBean;
    }

    @Override
    public Boolean findByItem(Integer userId, String gradeName) {
       UserBean userBean = mapper.findByItem(userId,gradeName);
         if(userBean==null){
             return false;
         }
        return true;
    }

    @Override
    public void add(UserBean userBean, int[] gradeIdArray) {
        mapper.addUser(userBean);
        mapper.addGrade(userBean.getUserId(),gradeIdArray);
    }


    @Override
    public UserBean findById(Integer userId) {
        UserBean userBean= mapper.findById(userId);
        return userBean;
    }

    @Override
    public void updGrade(Integer userId, int[] gradeIdArray) {
        mapper.updGrade(userId,gradeIdArray);
    }
}
